Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a switch on dev and staging to force offline mode #12135

Merged
merged 29 commits into from
Dec 1, 2022

Conversation

neil-marcellini
Copy link
Contributor

@neil-marcellini neil-marcellini commented Oct 25, 2022

cc @marcaaron since you wrote a lot of the network code.

Details

It's not possible to turn the network on and off on the iOS simulator, so I have added a toggle in the test tool menu to force the network to be offline. The toggle will only show on dev and on staging.

When the toggle is on the keys shouldForceOffline and isOffline are set to true under the network key in Onyx. When it is toggled off shouldForceOffline is set to false and we fetch the net info to set isOffline. When forced offline API.write requests will not send and will be added to the persisted queue for when the app comes back online. DeprecatedAPI requests will not send and all other requests will fail to fetch.

When the app is constructed the network is set to be offline, based on the value of shouldForceOffline. When the NetInfo state changes the offline status is set unless shouldForceOffline is true, which prevents the App from going online when shouldForceOffline is enabled. If you sign out while forcing offline, it will be disabled because otherwise there would be no way to go back online and sign in again, unless you refreshed the app.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/238637
PROPOSAL: N/A

Tests

A

  1. Sign into NewDot with any account
  2. If you don't already have a workspace, click the green plus at the bottom, New workspace
  3. Click the avatar in the header to go to settings
  4. Click Preferences
  5. Turn on the "Force offline" switch
  6. Hit the X at the top right to close the preferences
  7. Verify that you see the offline indicator at the bottom of the page
  8. Click the green plus at the bottom, New room
  9. Fill out the form and click "Create room".
  10. Verify that you are navigated to the room and it's grayed out (50% opacity)
  11. Refresh the page or kill the app and reopen it
  12. Verify you still see the offline indicator and the room is still grayed out
  13. Click the avatar in the header to go to settings
  14. Click Preferences
  15. Turn off the "Force offline" switch
  16. Go back to the room you created
  17. Verify you don't see the offline indicator and the room is no longer grayed out

B

  1. Sign into NewDot with any account
  2. Click the avatar in the header to go to settings
  3. Click Preferences
  4. Turn on the "Force offline" switch
  5. Click the back button at the top left
  6. Click sign out
  7. Wait about 5-10 seconds and verify that the offline indicator does not show up
  8. Verify that you are able to sign in again

C (web only)

  1. Open the dev tools and go to the console
  2. Hit command + f and search for "OpenApp"
  3. Find the second occurrence and verify that the OpenApp finished with code 200
  4. Go to preferences and force offline
  5. Refresh the page
  6. Find the second occurrence of OpenApp and verify that it "Failed to fetch".

D (web only)

  1. Open the dev tools and go to the Network tab
  2. Go offline
  3. Go back online and notice that ReconnectApp is called
  4. Go to Preferences and enable the force offline switch
  5. Disable the force offline switch and notice that ReconnectApp is called

Pusher

  1. Log in as account A
  2. Go to Preferences and enable the force offline switch
  3. Got to a chat with account B
  4. On another device log in as account B
  5. Send a chat to account A
  6. Go back to account A and verify that you did not receive the message, since you are forced offline
  7. Disable the force offline switch
  8. Go to the chat with account B and verify that you received the message
  • Verify that no errors appear in the JS console

QA Steps

Same as QA.

  • Verify that no errors appear in the JS console

PR Review Checklist

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above

  • I wrote clear testing steps that cover the changes made in this PR

    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms

  • I ran the tests on all platforms & verified they passed on:

    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)

  • I followed proper code patterns (see Reviewing the code)

    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers

  • I followed the guidelines as stated in the Review Guidelines

  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)

  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)

  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such

  • I verified that if a function's arguments changed that all usages have also been updated correctly

  • If a new component is created I verified that:

    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:

    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)

  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots

Web

A, B

web-A.B.mov

C, D

Web-C.D.mov

Pusher

Pusher.mov

Mobile Web - Chrome

android-chrome.mov

Mobile Web - Safari

ios-safari.mp4

Desktop

desktop.mp4

iOS

iOS.mp4

Pusher

iOS-Pusher.mov

Android

android.mov

@neil-marcellini neil-marcellini self-assigned this Oct 25, 2022
@thesahindia
Copy link
Member

I think this will do the job -

  1. Go to settings
  2. Go to preferences
  3. Turn on the "Force offline" switch
  4. Open a chat and verify you see offline indicator
  5. Send a message and verify it's grayed out
  6. Refresh the page and verify you still see the offline indicator
  7. Go to preferences
  8. Turn off the "Force offline" switch
  9. Go to the same chat again
  10. Verify you don't see the offline indicator
  11. Verify the earlier message is not grayed out

@neil-marcellini
Copy link
Contributor Author

@thesahindia thanks for writing up those steps. It turns out we have a bug on production resulting from these steps 🙈 , so I'm going to come up with different steps.

@neil-marcellini
Copy link
Contributor Author

I ran into a problem on iOS where the api command fails when going back online, which suggests that a duplicate request is getting sent somehow. I'll look into it another day.

iOS-fail.mp4

@neil-marcellini neil-marcellini marked this pull request as ready for review November 22, 2022 23:38
@neil-marcellini neil-marcellini requested a review from a team as a code owner November 22, 2022 23:38
@melvin-bot melvin-bot bot requested review from aldo-expensify and rushatgabhane and removed request for a team November 22, 2022 23:39
@melvin-bot
Copy link

melvin-bot bot commented Nov 22, 2022

@rushatgabhane @aldo-expensify One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@neil-marcellini neil-marcellini removed the request for review from rushatgabhane November 22, 2022 23:39
@neil-marcellini
Copy link
Contributor Author

@thesahindia I'm finally ready for a review on this. @rushatgabhane I unassigned you since he is already assigned.

@thesahindia
Copy link
Member

EOD for me. I will do the final testing in the morning.

@neil-marcellini
Copy link
Contributor Author

Ok, I'm hoping this is good to go now.

@thesahindia
Copy link
Member

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2022-11-29.at.6.44.41.PM.mov
Screen.Recording.2022-11-29.at.5.53.50.PM.mov
Screen.Recording.2022-11-29.at.5.36.44.PM.mov
Mobile Web - Chrome
Screen.Recording.2022-11-29.at.7.17.40.PM.mov
Screen.Recording.2022-11-29.at.7.16.30.PM.mov
Mobile Web - Safari
Screen.Recording.2022-11-29.at.7.06.53.PM.mov
Screen.Recording.2022-11-29.at.7.05.52.PM.mov
Desktop
Screen.Recording.2022-11-29.at.7.23.30.PM.mov
Screen.Recording.2022-11-29.at.7.21.25.PM.mov
iOS
Screen.Recording.2022-11-29.at.7.04.33.PM.mov
Screen.Recording.2022-11-29.at.7.02.11.PM.mov
Android
Screen.Recording.2022-11-29.at.7.13.30.PM.mov
Screen.Recording.2022-11-29.at.7.10.50.PM.mov

@thesahindia
Copy link
Member

Works well for me! Added a comment here.

@neil-marcellini
Copy link
Contributor Author

@aldo-expensify all you for a final review, thanks for all the help so far.

@neil-marcellini
Copy link
Contributor Author

Gentle bump @aldo-expensify

@aldo-expensify
Copy link
Contributor

Gentle bump @aldo-expensify

Sorry, I'll review again today

@aldo-expensify
Copy link
Contributor

aldo-expensify commented Nov 30, 2022

I'm not sure if this is a problem or not, but doing steps "C (web only)", I don't see "Failed to fetch"... where should I see that? I can see that the "Preview" and "Response" are empty, is that enough?

Screen.Recording.2022-11-30.at.3.39.34.PM.mov

Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested well, I agree with that it would be handy to have a shortcut or something, and I also agree with that this can be done in a follow up.

thanks for the work, it is useful to have an easy way of going offline in the IOS simulator

@aldo-expensify
Copy link
Contributor

@thesahindia approved I think, should we merge?

@neil-marcellini
Copy link
Contributor Author

I'm not sure if this is a problem or not, but doing steps "C (web only)", I don't see "Failed to fetch"... where should I see that? I can see that the "Preview" and "Response" are empty, is that enough?

@aldo-expensify yeah the "failed to fetch" error only shows in the console, you can see that in my testing video.

@neil-marcellini neil-marcellini merged commit 3342c39 into main Dec 1, 2022
@neil-marcellini neil-marcellini deleted the neil-switch-offline branch December 1, 2022 19:20
@OSBotify
Copy link
Contributor

OSBotify commented Dec 1, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Dec 2, 2022

🚀 Deployed to staging by @neil-marcellini in version: 1.2.36-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Dec 8, 2022

🚀 Deployed to production by @francoisl in version: 1.2.36-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@thesahindia
Copy link
Member

Hey @neil-marcellini, this is ready for payment can we get someone to create an upwork job. Here's a post about the process.

@neil-marcellini
Copy link
Contributor Author

Thanks for letting me know and including a post about the process. @puneetlath is assigned to handle your payment.

@puneetlath
Copy link
Contributor

@thesahindia I sent you a hiring offer via Upwork.

For me: https://www.upwork.com/nx/wm/pre-hire/c/8577561/offer/22655693

@puneetlath
Copy link
Contributor

Paid!

if (shouldForceOffline) {
Log.info('[Pusher] Ignoring a Push event because shouldForceOffline = true');
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coming from #28063, also check shouldForceOffline for sendEvent. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants